home *** CD-ROM | disk | FTP | other *** search
- Path: news4.noc.netcom.net!zdc!zippo!usenet
- Newsgroups: comp.lang.c
- Subject: Re: HELP! File Pointers
- Message-ID: <DKyzDM.FJ5@news.zippo.com>
- From: Jim McFarland <jgm6@orkand.em.cdc.gov>
- Date: Wed, 10 Jan 1996 14:39:21 GMT
- Sender: usenet@news.zippo.com
- References: <4csr4c$fem@newsbf02.news.aol.com>
- Organization: The Orkand Corporation
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- Nntp-Posting-Host: 158.111.166.77
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
- Mime-Version: 1.0
-
- roberino@aol.com (Roberino) wrote:
- >I am currently trying to keep one file open while opening other
- >files one at a time using a separate file pointer. However, as
- >soon as I read a line from the second file, the first file pointer
- >somehow gets destroyed and set to some position in the newly
- >opened file. Has anyone else encountered this? And if so,
- >is there a solution? (i.e. A way to protect the first file pointer
- >from being overwritten.)
- >
- >Here are the steps I am performing:
- >
- >void main()
- >{
- > FILE *File1;
- > FILE *File2;
- >
- > File1 = fopen("FILENAME", "r+");
- >
- > /* loop through lines in File1 using fgets() */
- >
- > if (Condition) /* just indicating some condition was met */
- > {
- > File2 = fopen("FILENAME2", "r+");
- >
- > fgets(Line, File2); <----- As soon as this occurs, File1 gets
- >
- > }
- >}
-
- Well, what is Line? You have not shown where Line is declared. It could
- be that Line is a pointer and memory is not allocated or it is too small
- and the fgets() overwrites File1 because of this. If you want help,
- don't condense your code so much. Due to the missing code, I am guessing
- as to what the problem is...
-
-